package com.slh.touchandroid.fragment;

import android.hardware.Camera;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageButton;

import com.slh.touchandroid.R;
import com.slh.touchandroid.utils.Utils;

public class LightFragment extends BaseFragment {
	// ==========================================================================
	private Camera mCamera;

	// ==========================================================================
	@Override
	public void onCreate(Bundle savedInstanceState) {
		setRetainInstance(true);
		super.onCreate(savedInstanceState);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View rootView = inflater.inflate(R.layout.fragment_light, container,
				false);
		mCamera = Utils.CameraHardware.getBackCamera();
		((ImageButton) rootView.findViewWithTag(getString(R.string.tag_light)))
				.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						v.setSelected(!v.isSelected());
						Utils.CameraHardware.setFlashEnabled(getActivity(), mCamera,
								v.isSelected());
					}
				});
		((ImageButton) rootView.findViewWithTag(getString(R.string.tag_light)))
				.performClick();
		return rootView;
	}

	@Override
	public void onPause() {
		Utils.CameraHardware.releaseCamera(mCamera);
		super.onPause();
	}

	@Override
	public void onDestroy() {
		Utils.CameraHardware.releaseCamera(mCamera);
		super.onDestroy();
	}
	// ==========================================================================
}
